#ifndef XMLCLIENT_HH_
# define XMLCLIENT_HH_
# include "Network.hh"
# include "ClientState.hh"
# include "GameList.hh"
# include "StateChanged.hh"
# include "../Gui/Gui.hh"
# include "../Geom/Vector.hh"
# include <QtCore>

class Network::XmlClient: public QObject {
    Q_OBJECT

	protected: static XmlClient* client;

	public: static XmlClient& instance();

    protected: ClientState state;

    protected: XmlSocket socket;

    protected: QString username;

    protected: QString key;

    protected: QString certificate;

    protected: QString ca;

    protected: Gui::ConnectWindow* connectWindow;

    protected: Gui::MainWindow* mainWindow;

    protected: Gui::GameWindow* gameWindow;


    public: XmlClient();

    public: void ssl_config(QString key_path, QString cert_path, QString ca_path);

    public: void start();

    public: void show_main_window();

    public: void show_game_window();

    public: void process_game_list(GameList::GameListInfo const& gameListInfo);

    public: ClientState get_state() const;

    public: void set_state(ClientState value);

    public: XmlSocket& get_socket();

    public: void message(QString);

    public: void flotta_kival(Gui::Flotta*);

    public: void chat_msg_received(QString sender, QString msg);

    protected slots:
    void connect_to_server(QString host, u2 port);

    protected slots:
    void socket_state_changed(QAbstractSocket::SocketState socketState);

    protected slots: void process_message();

    public: void clear();

    public: void show_fleet(Network::StateChanged::FleetInfo, QString);
    public: void show_star(Network::StateChanged::StarInfo const&);

    public: void move_selected_fleet(Geom::Vector<> pos);

    public: QString get_name();

    signals: void state_changed(ClientState);

    signals: void game_list_rcvd(Network::GameList::GameListInfo gameListInfo);

    protected slots: void send_new_game(QString name, u2 min, u2 max);

    protected slots: void send_new_turn();

    public slots: void refresh_game_list();

    public slots: void send_chat_msg_to_server(QString msg);

    public slots: void send_join(QString);

    protected slots: void send_attack_fleet(
      Gui::Flotta* attacker, Gui::Flotta* target
    );
    protected slots: void send_attack_planet(
      Gui::Flotta* attacker, u8 starId, Gui::Bolygo* target
    );
    protected slots: void send_colonize_planet(
      Gui::Flotta* fleet, u8 starId, Gui::Bolygo* target
    );
    protected slots: void send_add_task(
      Gui::Csillag* star, Gui::Bolygo* planet, QString what, u8 count
    );
};

#endif // ndef XMLCLIENT_HH_
